<script>
import {
		AVATARURL,
		HNIT_URL,
		MONITOR,
		STUNAME,
		USERNAME,
		IDENTITY,
		TNAME,
		SESSION_KEY,
		OPENID,
		WXNAME
	} from "@/constants/index.js";

	import {
		$request
	} from 'common/uni_request.js'
	export default {
		data(){
			return{
				code:""
			}
		},onLoad() {
			wx.loadFontFace({
				family: 'FZSuXSLSJW',
				source: 'url("https://static.heytea.com/taro_trial/v1/font/WenYue-XinQingNianTi-NC-W8_1.otf")',
				success: res => {},fail: err => {}})
		},
	
		onLaunch: function() {
			//查找用户
			let username =  uni.getStorageSync(USERNAME)
			if(username!=""){
				let params={
					username:username
				}
				//查询上次登录在redis里面的剩余时间
				this.$request.post(HNIT_URL+"wx/queryTime",params).then(res=>{
					//过期处理
					if(res.code==0){
						uni.removeStorageSync(WXNAME)
						uni.removeStorageSync(AVATARURL)
						uni.removeStorageSync(SESSION_KEY)
						uni.removeStorageSync(OPENID)	
						uni.removeStorageSync(MONITOR)
						uni.removeStorageSync(TNAME)
						uni.removeStorageSync(IDENTITY)
					}
				})	
			}
			
			var session_key = uni.getStorageSync(SESSION_KEY)
			//判断如果session_key存在，加时长并且跳转页面
			if (session_key != "") {
				let params = {
					username:username
				}
			//刚进入小程序就给对应的用户加时间
			this.$request.post(HNIT_URL+"wx/addTime", params).then(res => {
			}, err => {
			})
			//获取缓存当中的身份Id ，  根据id直接跳转
				let ID= uni.getStorageSync(IDENTITY)
				if(ID==0){
					uni.reLaunch({
						url:"pages/student/home/index"
					})
				}else if (ID==3){
					uni.reLaunch({
						url:"pages/teacher/home/index"
					})
					
				}else if(ID==1){
					uni.reLaunch({
						url:"pages/manage/home/index"
					})
				}else if(ID==4){
					uni.reLaunch({
						url:"pages/manage/home/index"
					})
				}
			}
		},
		onShow: function() {
		},
		onHide: function() {
		},
	}
</script>


<style lang="scss">
	/*每个页面公共css */
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";

	@font-face {
	  font-family: 'FZSuXSLSJW';  // 此处填写你的字体名称
	  src: url('https://static.heytea.com/taro_trial/v1/font/WenYue-XinQingNianTi-NC-W8_1.otf');  // 此处填写你字体文件的路径
	}
</style>